<template>
    <div class='timeListBox'>
        <el-dialog
            title="选择时间"
            :visible.sync="dialogVisible"
            width="40%"
            @close="handleClose"
        >
            <div class="timeListDiv">
                <div @click="selectFun(index)" :class="item.is_me == 1?'avater':''" v-for="(item, index) in timeArr" :key="index">{{item.time_f1}}~{{item.time_t1}}</div>
            </div>
            <span slot="footer" class="dialog-footer">
                <el-button @click="dialogVisible = false">取 消</el-button>
                <el-button type="primary" @click="pushtimeData">确 定</el-button>
            </span>
        </el-dialog>
    </div>
</template>

<script>
// import xxx from '@/components/comm/xxx.vue';
export default {
    props: [

    ],
    components: {

    },
    computed: {

    },
    data() {
        return {
            dialogVisible: false, // 是否显示
            timeArr: [], // 时间段列表
            time_ls: [], // 选中时间段列表
        };
    },
    created() {

    },
    mounted() {

    },
    methods: {
        timeLsFun () {
			let copyArr = JSON.parse(JSON.stringify(this.timeArr));
            copyArr.forEach( (item,index) => {
                this.time_ls.forEach( (row,i) => {
                    if (item.time_f1 === row.time_f1) {
						item.is_me = 1;
                        this.timeArr = copyArr;
                    }
                })
            })
        },
        selectFun (i) { // 选中时间段
            let copyArr = JSON.parse(JSON.stringify(this.timeArr));
            copyArr[i].is_me = copyArr[i].is_me == 1? 2:1;
            this.timeArr = copyArr;
        },
        pushtimeData () { // 提交选中时间数据
            let mapArr =  this.timeArr.filter( item=> {
                return item.is_me == 1
            })
            mapArr = mapArr.map( item => {
                return {
                    time_f1: item.time_f1,
                    time_t1: item.time_t1,
                }
            })
            console.log(mapArr,'mapArrmapArr')
            this.$emit("pushtimeData", mapArr)
            this.dialogVisible = false;
        },
        handleClose(done) {
            this.dialogVisible = false;
        }
    }
};
</script>

<style lang="scss" scoped >
.timeListBox {
    .timeListDiv {
        width: 100%;
        display: flex;
        flex-wrap: wrap;
        >div {
            width: 100px;
            height: 30px;
            line-height: 30px;
            text-align: center;
            flex-shrink: 0;
            border: 1px solid #DCDFE6;
            margin: 0 10px 10px 0;
            border-radius: 4px;
            cursor: pointer;
        }
        .avater {
            background: #3388ff;
            color: #FFFFFF;
        }
    }
}
</style>
